package com.qf.fmall2202.service.impl;

import com.qf.fmall2202.entity.Category;
import com.qf.fmall2202.mapper.CategoryMapper;
import com.qf.fmall2202.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品分类 服务实现类
 * </p>
 *
 * @author author
 * @since 2022-11-03
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

	@Override
	public List< Category > getCategorylist( ) {
		//查出所有的分类的商品
		List< Category > list=this.list( );

		//遍历商品菜单
		for(Category category: list) {
			List< Category > categories=new ArrayList<>( );
			category.setCategoryList( categories );
			for(Category category1: list) {
				if(category1.getParentId().equals( category.getCategoryId() )){
					categories.add( category1 );
				}
			}
		}

		//再遍历一遍把没有子集合的商品给删除掉
		ArrayList< Category > categories=new ArrayList<>( );
		for(Category category: list) {
			if(category.getCategoryLevel()==1){
				categories.add( category );
			}
		}
		return categories;
	}
}
